/**
 * Copyright (C), 2021, 因特驰
 * FileName: TreeServiceImpl
 * Author:   李晋武
 * Date:     2021/7/13 16:39
 * Description:
 * History:
 * 李晋武          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.esc.service.impl;

import com.esc.mapper.TreeMapper;
import com.esc.model.Tree;
import com.esc.service.TreeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 〈一句话功能简述〉<br> 
 * 〈〉
 *
 * @author Yun
 * @create 2021/7/13
 * @since 1.0.0
 */
@Service
public class TreeServiceImpl implements TreeService {

    @Autowired
    private TreeMapper treeMapper;

    @Override
    public List<Tree> queryTreeList() {
        return queryTreeListByPid(0);
    }

    private List<Tree> queryTreeListByPid(int pid) {
        List<Tree> treeList = treeMapper.queryTreeListByPid(pid);
        for (Tree t: treeList) {
            List<Tree> trees = queryTreeListByPid(t.getId());
            if(trees==null || trees.size()<=0){
                t.setSelectable(true);
            }else {
                t.setNodes(trees);
                t.setSelectable(false);
            }
        }
        return treeList;
    }

}